/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import java.io.*;
import java.util.*;

/**
 *
 * @author Diogo
 */
public class SaveGame implements Serializable{
    
    private List<Profile> profiles;
    
    public SaveGame(){
        profiles = new ArrayList<Profile>();
    }
    
    public void salvarProfile(Profile profile){
        int index = profiles.indexOf(profile);
        if(index > -1){
            profiles.set(index, profile);
        }else{
            profiles.add(profile);
        }
    }
    
    public Profile getProfile(String nome){
        for(Profile f : profiles){
            if(f.getNome().equals(nome)){
                return f;
            }
        }
        return null;
    }
    
    public void salvar(){
        Utils.salvarArquivo(this, Utils.CAMINHO);
    }
    
    public static SaveGame abrirSaveGame(){
        SaveGame svg = Utils.abrirArquivo(Utils.CAMINHO);
        if(svg == null){
            svg = new SaveGame();
        }
        return svg;
    }
    
}
